﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;



namespace FuseTester
{
    class Sprite : Game
    {
        protected GraphicsDeviceManager graphics;
        //MouseCursor mouseCursor;

        public Vector2 Position = new Vector2(0, 0);       
        private Texture2D SpriteTexture;
        private Vector2 Scale = Vector2.One;
        public Rectangle Size;
        public Boolean exists = true;
        public Color spriteColor = Color.White;
        //private Viewport viewport = gra

        //protected int widthBound;
        //protected int heightBound;
        //private int xPosition;
        //private int yPosition;

        public Sprite()
        {
        }

        public Sprite(GraphicsDeviceManager graphics)
        {
            this.graphics = graphics;
        }

        
            

        //Load the texture for the sprite using the Content Pipeline
        public void LoadContent(ContentManager contentManager, string assetName)
        {
            graphics = new GraphicsDeviceManager(this);

            
            SpriteTexture = contentManager.Load<Texture2D>(assetName);
            Size = new Rectangle(0, 0, (int)(SpriteTexture.Width * Scale.X), (int)(SpriteTexture.Height * Scale.Y));

            //heightBound = Size.Height / 2;
            //widthBound = Size.Width / 2;        
        }

        public void Draw(SpriteBatch spriteBatch)
        {
            //Rectangle rec = new Rectangle(0, 0, SpriteTexture.Width, SpriteTexture.Height);
            spriteBatch.Begin();

            spriteBatch.Draw(SpriteTexture, Position, Size, spriteColor, 0.0f, Vector2.Zero, Scale, SpriteEffects.None, 0);

            spriteBatch.End();
            //spriteBatch.Draw(SpriteTexture, Position, Color.White);
        }

        public void SetColor(Color color)
        {
            spriteColor = color;
        }

        public void SetScale(Vector2 val)
        {
            Scale = val;
            //Scale = Scale + val;
            Size.Width = Convert.ToInt32( (float)Size.Width * Scale.X);
            Size.Height = Convert.ToInt32( (float)Size.Height * Scale.Y);
            //Size = new Rectangle(0, 0, (int)(SpriteTexture.Width * Scale), (int)(SpriteTexture.Height * Scale));
        }

        public int SetX(int x)
        {
            int retVal = 0;

            //check for x bounds
            if ((graphics.PreferredBackBufferWidth - (this.Size.Width / 4)) > x
                && x > 0 || true)
            {
                //xPosition = x;
                Position = new Vector2(x, Position.Y);
            }
            else
            {
                retVal = -1;
            }

            return retVal;
        }

        public int SetY(int y)
        {
            int retVal = 0;

            //check for y bounds
            if ((graphics.PreferredBackBufferHeight - (this.Size.Height / 4)) > y
                && y > 0 || true)
            {
                //yPosition = y;
                Position = new Vector2(Position.X, y);
            }
            else
            {
                retVal = -1;
            }

            return retVal;
        }

        
    }   

}
